home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / CrashHandling.Lib next >
Encoding:
Text File  |  1998-03-19  |  23.1 KB  |  592 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        CrashHandling.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA
  9. #
  10. #    Copyright:    © 1995-1996 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    1.0.112>     6/18/96    MDF        Added global gIsBothMethods to check check for both test case
  19. #                                    handling methods.  This is a boolean value.
  20. #    .0.111+>     6/18/96    MDF        Changing to correctly handle both test case logging methods.
  21. #    1.0.111>    11/15/95    ML        InstallEveryTimeMacro() - check $bff to see if macsbug is
  22. #                                    installed, replaced Debug with _Debug
  23. #    .0.110+>    11/14/95    ML        InstallEveryTimeMacro - check to see if macsbug is installed and
  24. #                                    running
  25. #    1.0.110>     5/23/95    ML        Merge in changes for Clouseau compatibility
  26. #    1.0.19+>     5/23/95    ML        
  27. #    <1.0.19>     5/18/95    ML        Don't try gathering w/Applescript if not using Results Express
  28. #                                    method
  29. #    1.0.18+>     5/17/95    ML        
  30. #    <1.0.18>     5/17/95    ML        removed trace() call in GatherTargetCrashLog
  31. #    1.0.17+>     5/17/95    ML        removed trace() call in GatherTargetCrashLog
  32. #    <1.0.17>     5/16/95    ML        GatherTargetCrashLog()-if crash log exists, rename it first,
  33. #                                    using GetRenameCrashLogAs or gapptitle and time to create new
  34. #                                    name, concat new name if too long, base success/fail on
  35. #                                    renaming.  create crash log subfolder based on target name and
  36. #                                    date, concat if too long, copy renamed crash log to it.
  37. #                                    consolidated printing log onto output window into single set of
  38. #                                    calls.  DefaultCrashHandler()- Calls global
  39. #                                    gConfirmReacquireTarget hook during reacquire phase.
  40. #                                    GatherWithAppleScript() - replace gCrashLog with new global
  41. #                                    name.
  42. #    1.0.16+>     5/12/95    ML        various enhancements for Clouseau merge
  43. #    <1.0.16>     4/25/95    KTA        GatherTargetCrashLog() - if we can't verify the crashLogs folder
  44. #                                    then we don't continue.
  45. #    <1.0.15>     3/30/95    KTA        GatherTargetCrashLog() - added the Macsbug commands to output.
  46. #    <1.0.14>     3/30/95    KTA        GatherTargetCrashLog() - Removed a call to _FileTool(
  47. #                                    "CopyFile").
  48. #    <1.0.13>     3/29/95    KTA        Deleted _GatherTargetCrashLog(), rolled funtionality into
  49. #                                    GatherTargetCrashLog(), added GatherWithAppleScript().
  50. #    <1.0.12>     3/28/95    ML        _GatherTargetCrashLog() - added a QuitFileTool() call.
  51. #    <1.0.11>     2/28/95    KTA        InstallEveryTimeMacro() - Default pMacroCommands to global
  52. #                                    gMacroCommands try block around DebugStr() call, Quit FileTool
  53. #                                    if Macsbug is not installed.
  54. #     <1.0.9>     2/28/95    ML        Marked.
  55. #     <1.0.9>     2/28/95    KTA        Able to suspend if target is hung.
  56. #     <1.0.7>     2/22/95    KTA        Added marks
  57. #     <1.0.6>     2/16/95    KTA        InstallEveryTimeMacro() - Check for Macsbug 6.5xx, and insure
  58. #                                    macsbug is installed.
  59. #     <1.0.5>     2/16/95    ML        DefaultCrashHandler() - Host will beep if execution suspended,
  60. #                                    Call ReacquireTarget with global gMachineName.
  61. #                                    ReacquireTarget() - default pTargetName to global gTargetname
  62. #     <1.0.4>     2/13/95    KTA        InstallEveryTimeMacro() - Removed extra Printlns, check version
  63. #                                    of Macsbug, Quit Filetool.
  64. #     <1.0.3>      2/3/95    KTA        Added the ability to throw when the crashHandler completes
  65. #     <1.0.1>     1/31/95    KTA        Removed a Trace() call.
  66. #
  67. # ****************************************************************************
  68. Libraries "Results Express.lib","FileToolOperations.lib","TCS.lib","ExceptionHandling.Lib","Output.Lib",
  69. "String.Lib", "MemoryMonitorOperations.Lib";
  70. #########################################################################
  71. #    GatherTargetCrashLog( pErrorCode, pAbortSuite, pAppleScriptMethod )
  72. #========================================================================
  73. # Author:        KTA 
  74. # Description:    1) Initializes filetool on the target.
  75. #                2) checks to see if a file named "CRASHLOG" exists on the root
  76. #                   of boot vol.
  77. #                3) Moves a copy of the macsbug data to 'CrashLogs ƒ' on the root.
  78. #                4) Reads the file using FileTool
  79. #                5) Writes a testcase that includes the data using ResultsExpress.
  80. #                6) Deletes the working copy of the file
  81. #                Note: Step 4 and 5 may be controlled with either AppleScript
  82. #                    or VU.  AppleScript is the preferred method as VU has a 
  83. #                    2000 character string limit.  If the AppleScript method fails,
  84. #                    we try again using VU.
  85. #                    
  86. # Parameters:    pErrorCode - The error code that VU recieved when it 1st detected 
  87. #                            the crash.
  88. #                pAbortSuite - a Flag to indicate whether we wish to abort
  89. #                                the current suite because of the crash.
  90. #                pAppleScriptMethod - a flag used to indicate whether to use
  91. #                            AppleScript or not (for initiating steps 3 and 4 only).
  92. # Returns:        Nothing
  93. # Examples:        GatherTargetCrashLog( -1100, 1)
  94. # Assumptions:    
  95. #########################################################################
  96. #========================================================================
  97. # History:
  98. # KTA    3/29/95     Created
  99. # KTA    3/29/95     Removed a call to _FileTool( "CopyFile")  that was left
  100. #                    in accidentally.
  101. # KTA    3/29/95     added gMacroCommands
  102. # KTA    4/25/95     if we can't verify the crashLogs folder then we don't continue.
  103. # ML    5/16/95        if crash log exists, rename it first, using GetRenameCrashLogAs
  104. #                    or gapptitle and time to create new name, concat new name if
  105. #                    too long, base success/fail on renaming. 
  106. # ML    5/16/95        create crash log subfolder based on target name and date,
  107. #                    concat if too long, copy renamed crash log to it.
  108. # ML    5/16/95        consolidated printing log onto output window into single
  109. #                     set of calls
  110. # ML    5/18/95        Don't try gathering w/Applescript if not using
  111. #                    Results Express method
  112. # MDF    06/18/96    Added global gIsBothMethods to check for both test case
  113. #                    logging methods.
  114. #########################################################################
  115. Task GatherTargetCrashLog( pErrorCode, pAbortSuite := 1, pAppleScriptMethod := 1 )
  116. begin
  117.     global gTestCaseLoggingMethod, kTCSResultsExpressMethod, gIsBothMethods;
  118.  
  119.     tSuccessFlag := false;
  120.     successWithApplescript := false;
  121.     theData := 0;    
  122.     filetoolInit :=  _FileTool( "initialize", {1},true);
  123.     if(filetoolInit[1] = 0)
  124.     begin
  125.         doesExist :=  _FileTool( "FileExists", {global gCrashLog},true);
  126.         if(doesExist[1] = 0)
  127.         begin
  128.             newCrashLogName := GetRenameCrashLogAs();
  129.             if not newCrashLogName
  130.             begin
  131.                 if not (global gapptitle)
  132.                     newCrashLogName := "unknown";
  133.                 else
  134.                     newCrashLogName := gapptitle;
  135.             end;
  136.             try
  137.                 match [time m:?month d:?day h:?Tm];
  138.             catch theErr
  139.                 ExceptionDispatcher(theErr);
  140.             newCrashLogName := ConcatNameString(newCrashLogName, " {Tm}", 31);
  141.             RenamedFile := _FileTool( "Rename", {global gCrashLog,0,newCrashLogName},true);
  142.             if (RenamedFile[1] = 0)
  143.             begin
  144.                 tSuccessFlag := true;        # Success
  145.                 logstr("Renamed the Macsbug log file '{gCrashLog}' to '{newCrashLogName}'",1,'RStatus');
  146.  
  147.                 ## Copy the Macsbug datafile into a folder for posterity and work  
  148.                 ##  with a disposable copy of it
  149.  
  150.                 if (ExistsOrCreate("{global gBootVol}:CrashLogs ƒ:"))
  151.                 begin
  152.                     newCrashLogSubFolder := ConcatNameString(global gMachineName, " {month}/{day}", 31);
  153.                     ExistsOrCreate
  154.                     ("{global gBootVol}:CrashLogs ƒ:{newCrashLogSubFolder}:");
  155.  
  156.                     ##  Move a copy of the file into the 'CrashLogs ƒ' folder
  157.  
  158.                     theCopy := _FileTool( "CopyFile",{"{global gBootVol}:{newCrashLogName}", 0,
  159.                     "{global gBootVol}:CrashLogs ƒ:{newCrashLogSubFolder}:{newCrashLogName}"} );
  160.                     if (theCopy[1] = 0)
  161.                     begin
  162.                         LogStr("The crash log file named '{newCrashLogName}' has been copied
  163.                         to the folder '{gBootVol}:CrashLogs ƒ:
  164.                         {newCrashLogSubFolder}'",1,'RStatus');
  165.                         global gfullPathCrashLogName := "{global gBootVol}:{newCrashLogName}";
  166.  
  167.                         ## Use AppleScript to read the file and write the testcase 
  168.                         ## Note: We try to use applescript, if it fails for any reason
  169.                         ##       we try again using VU (vu is limited to the 1st 2000 chars).
  170.  
  171.                         if(pAppleScriptMethod)
  172.                         begin 
  173.                             pTCSpecifier :=     {2,"Crash Handler","Compatibility","SPEC S&L",
  174.                                                 "CRASH occurred on target - AppleScript", -3};
  175.                             if ((gTestCaseLoggingMethod = kTCSResultsExpressMethod) or gIsBothMethods)
  176.                             begin
  177.                                 if(GatherWithAppleScript( pErrorCode , pTCSpecifier))
  178.                                     successWithApplescript := true;
  179.                                 else
  180.                                     println "NOTE: Problem gathering with AppleScript.  Will attempt
  181.                                     to gather 1st 2000 chars of Macsbug data using VU instead.";
  182.                             end;
  183.                             else
  184.                                 println("Can't gather log using Applescript method because your
  185.                                 test case tracking method isn't set to 'Results Express'.");
  186.                         end; # if(pAppleScriptMethod)
  187.     
  188.                         ## Use VU to read the file (note: only first 2000 chars)
  189.  
  190.                         theDataList := _FileTool('Read',{gfullPathCrashLogName,0,2000,0}, true);
  191.                         DeleteTheFile(gfullPathCrashLogName);
  192.                         QuitFileTool();             # need to quit here because we clean
  193.                                                     # abort out of TCSEnd
  194.                         if(theDataList[1] = 0)
  195.                             theData := theDataList[2];
  196.                         else
  197.                             println "Couldn't READ bytes ",theDataList[1], theDataList[3] ;
  198.                         LogStr("••••••••• ERROR:CRASH occurred on target ••••••••
  199.                                 The commands that were issued in Macsbug are
  200.                                 '{global gMacroCommands}'.");
  201.                     
  202.                         if (successWithApplescript)
  203.                         begin
  204.                             logstr("Gathered Macsbug log using AppleScript ");
  205.                             if (theData)
  206.                             begin
  207.                                 logstr("The following output is the first 2000 chars:" );
  208.                                 println "∂n", theData;
  209.                             end;
  210.                         end;
  211.                                             
  212.                         ## Abort the suite if desired
  213.                         if(successWithApplescript and pAbortSuite)
  214.                             CleanAbort('CRASH occurred on target', pAbortSuite);
  215.                             
  216.                         if not(pAppleScriptMethod) or (pAppleScriptMethod and not
  217.                                                         successWithApplescript)
  218.                         begin
  219.                             TCSStart({ 1, "Crash Handler" },"CRASH occurred on target",,0);
  220.                                 # Start TCS (but don't match the target)
  221.                             TCSEnd({ 1, "Crash Handler" }, -3,,pErrorCode,"{theData}",
  222.                                     global gMachineName,pAbortSuite);
  223.                         end;
  224.                     end; # if (theCopy[1] = 0)
  225.                     else 
  226.                     begin
  227.                         println "Error Copying file ";
  228.                         Println "Error : ", theCopy[1], " , ", theCopy[3];
  229.                     end;
  230.                 end; # ExistsOrCreate("{global gBootVol}:CrashLogs ƒ:")
  231.                 else
  232.                     println "Error while checking for '{global gBootVol}:CrashLogs ƒ:' folder";
  233.             end; # RenamedFile[1] = 0
  234.             else
  235.             begin
  236.                 println "Problem renaming file '{gCrashLog}' to '{newCrashLogName}'";
  237.                 Println "Error : ", RenamedFile[1], " , ", RenamedFile[3];
  238.             end;
  239.         end; # if(doesExist[1] = 0) 
  240.         else
  241.         begin
  242.             println "File '{gCrashLog}' does not exist";
  243.             Println "Error : ", doesExist[1], " , ", doesExist[3];
  244.         end;
  245.     end;
  246.     else
  247.     begin
  248.         println "Error initializing FileTool";
  249.         Println "Error : ", filetoolInit[1], " , ", filetoolInit[3];
  250.     end;
  251.     
  252.     QuitFileTool(); 
  253.     return(tSuccessFlag);
  254. end;
  255.  
  256.         
  257. #########################################################################
  258. #                GatherWithAppleScript( pErrorCode, pTCSpecifier )
  259. #========================================================================
  260. # Author:        KTA 
  261. # Description:    Steps 4 and 5 of GatherTargetCrashLog() using AppleScript
  262. #                1) …
  263. #                2) …
  264. #                3) …
  265. #                4) Reads the file using FileTool
  266. #                5) Writes a testcase that includes the data using ResultsExpress.
  267. #                    
  268. # Parameters:    pErrorCode - The error code that VU recieved when it 1st detected 
  269. #                            the crash.
  270. #                pTCSpecifier - The data used to identify the testcase if the form:
  271. #                                {Number,"Set","Type","Owner","Description", Result}
  272. # Returns:        true - succesful
  273. #                false - an error occured
  274. # Examples:        GatherWithAppleScript( -1100 , {2,"Set","Type","Owner","Description", -3});
  275. #
  276. # Assumptions:    
  277. #########################################################################
  278. #========================================================================
  279. # History:
  280. # KTA    3/39/95     Created
  281. # ML    5/16/95        replace gCrashLog with gfullPathCrashLogName
  282. #########################################################################
  283. task GatherWithAppleScript( pErrorCode, pTCSpecifier)
  284. begin
  285.     #println "pErrorCode - ", pErrorCode;
  286.     #println "global gCurSuiteID - ", global gCurSuiteID;
  287.     #println "global gCrashLog - ", global gCrashLog;
  288.     #println "gMachineName - ", global gMachineName;
  289.     
  290.     theScript :=  
  291.     'on DoGather( pErrorCode, pParentSuite, pCrashLogPath, pMachineName, pTCID )
  292.         try
  293.             beep
  294.             tell application "FileTool" of machine "' + "{global gMachineName}" +  '"
  295.                 try
  296.                     set CrashLogData to DoService "Read" Parameters {pCrashLogPath, 0, 32000, 0}
  297.                     beep
  298.                 on error errMsg number ErrCode
  299.                     display dialog ("Read failed " & ErrCode as string) & " : " & errMsg
  300.                     error {ErrCode, errMsg}
  301.                 end try
  302.             end tell
  303.             
  304.             set kTestCaseRecord to 4
  305.             try
  306.                 tell application "Results Express"
  307.                     set x to DoService "NewRecord" Parameters ¬
  308.                         {kTestCaseRecord, pParentSuite, ¬
  309.                             {    {"TCNo",         Item 1 of pTCID}, ¬
  310.                                 {"TCSet",         Item 2 of pTCID}, ¬
  311.                                 {"TCType",         Item 3 of pTCID}, ¬
  312.                                 {"TCOwner",     Item 4 of pTCID}, ¬
  313.                                 { "TCDesc",        Item 5 of pTCID},¬
  314.                                 { "Result",         Item 6 of pTCID},¬
  315.                                 { "NumericVal",    pErrorCode }, ¬
  316.                                 { "Comments",    pMachineName },¬
  317.                                 {"TextVal",     CrashLogData} ¬
  318.                                 } ¬
  319.                                 }
  320.                     beep
  321.                 end tell
  322.             on error errMsg number ErrCode
  323.                 display dialog ("NewRecord failed " & ErrCode as string) & " : " & errMsg
  324.                 error {ErrCode, errMsg}
  325.             end try
  326.             beep
  327.             return true
  328.         on error errMsg number ErrCode
  329.             return false
  330.         end try
  331.     end 
  332.     DoGather("' 
  333.     + "{pErrorCode}" 
  334.     + '", "' + "{global gCurSuiteID}" 
  335.     + '", "' + global gfullPathCrashLogName 
  336.     + '", "' + global gMachineName 
  337.     + '", ' 
  338.     + "{pTCSpecifier}"
  339.     + ' )';        
  340.     
  341.     
  342.     # End AppleScript string
  343.  
  344.     #Println "Length of AppleScript - ",Card(theScript);
  345.     #Println "AppleScript - '", theScript,"'";
  346.     x := AppleScriptString( theScript );
  347.     #Println "This is the call to AppleScriptString() - ", x;
  348.     if(x[1] = 0)
  349.         return (true);
  350.     else 
  351.     begin
  352.         Println "!@#$% Problem trying to run AppleScript to gather Macsbug Data";
  353.         Println "Error : ", x[1], " , ", x[3];
  354.         return(false);
  355.     end;
  356. end;
  357.  
  358. #########################################################################
  359. #                DefaultCrashHandler(pParamList)
  360. #========================================================================
  361. #    Description:    simple Crash handler prototype
  362. #    Parameters:        pParamList:    list of parameters
  363. #                        element 1 := What to do about the suite(1 - Fail the suite/0 don't fail the suite)
  364. #                        element 2 := What to do if can't aquire target (1 - abort script/0-suspend)
  365. #                        element 3 := What to do if can't gather crashlog (1 - abort script/0-turn off crashHandler but continue)
  366. #                        element 4 := [optional] Throw when done or not - will throw whatever it is defined as
  367. #    Returns:        result of error handler TASK call, or throw if fatal
  368. #    Examples:        DefaultCrashHandler({1})
  369. #    Assumptions:    VU 2.1
  370. #========================================================================
  371. #    History:
  372. #    ML    2/16/95    Host will beep if execution suspended
  373. #                Call ReacquireTarget with global gMachineName
  374. #    ML    5/12/95    added hook for additional testing to confirm reacquire
  375. #    KTA    5/17/95    Added support for AIQ logging
  376. #########################################################################
  377. TASK DefaultCrashHandler(pErrID, pParamList := {1,1,1})
  378. begin
  379.     LogStr("DefaultCrashHandler() - error is {pErrID} : {pParamList}", 4, 'RStatus');    # call with support for AIQ logging
  380.         
  381.     println "global gMachineName", global gMachineName;
  382.     ## LOG SOME INFO 
  383.     if not(_matchBoolean([target t:global gMachineName]!))
  384.     begin
  385.         LogStr("DefaultCrashHandler() - Target failure (error = {pErrID})", 4, 'RError');    # call with support for AIQ logging
  386.         LogStr("DefaultCrashHandler() - Target '{global gMachineName}' CRASHED! WAITING FOR RESTART TO CONTINUE SCRIPT…", 1, 'RStatus');    # call with support for AIQ logging
  387.     end;
  388.     else if(pErrID = -1096)        # Target Restarted
  389.     begin
  390.         LogStr("DefaultCrashHandler() - Target failure (error = {pErrID})", 4, 'RError');    # call with support for AIQ logging
  391.         LogStr("DefaultCrashHandler() - Target '{global gMachineName}' RESTARTED UNEXPECTEDLY!", 1, 'RStatus');    # call with support for AIQ logging
  392.     end;
  393.     else
  394.     begin
  395.         LogStr("DefaultCrashHandler() - Target failure (error = {pErrID})", 4, 'RError');    # call with support for AIQ logging
  396.         LogStr("DefaultCrashHandler() - Target '{global gMachineName}' FAILED AND THEN RECOVERED", 1, 'RStatus');    # call with support for AIQ logging
  397.     end;
  398.                 
  399.     if not(ReacquireTarget(global gMachineName))
  400.     begin
  401.         if not(pParamList[2])            # Pause until user resets target
  402.         begin
  403.             pParamList[1] := 0;
  404.             LogStr("DefaultCrashHandler() - Please reset the Target",1, 'RStatus');
  405.             while not(ReacquireTarget(global gMachineName))        # Wait forever
  406.                 sysbeep();
  407.         end;
  408.         else
  409.         begin
  410.             LogStr("DefaultCrashHandler() - Target crashed and we can't reaquire it",1,'RStatus');;
  411.             TCSStart({ 2, "Crash Handler" },"CRASH occurred on target",,0);    # Start TCS (but don't match the target)
  412.             TCSEnd({ 2, "Crash Handler" }, -3,"Cannot reaquire target - aborting suite",,,global gMachineName,-2);
  413.             return;
  414.         end;
  415.     end;
  416.     
  417.     ## This is the hook to do a second restart
  418.     if global gConfirmReacquireTargetHook
  419.         call (gConfirmReacquireTargetHook);
  420.         
  421.     ## Determine if you want to abort the suite if there was a crash
  422.     if(pParamList[1])
  423.         AbortSuite := -2;        # Abort the suite
  424.     else
  425.         AbortSuite := '';
  426.         
  427.     ## Gather the Crash log and put it into a TCS
  428.     if not(GatherTargetCrashLog(pErrID, AbortSuite))
  429.     begin
  430.         if(pParamList[3])
  431.             AbortSuite := -2;        # Abort the suite
  432.         else
  433.             AbortSuite := '';
  434.  
  435.         LogStr("Target crashed and we couldn't gather the Macsbug Log",1,'RStatus');
  436.         TCSStart({ 3, "Crash Handler" },"CRASH occurred on target",,0);
  437.         TCSEnd({ 3, "Crash Handler" }, -3,"Cannot gather the Macsbug Log",,,global gMachineName,AbortSuite);
  438.         if(AbortSuite = -2)
  439.             return;
  440.     end;
  441.     
  442.     ## Clear stack, and reinstall macro if you didn't want to abort the suite
  443.     if (AbortSuite <> -2)                  # Only if pParamList[1] = 0 (Don't abort suite if crash)
  444.     begin
  445.         ClearStack();
  446.         InstallEveryTimeMacro();        # Send the Debug string used by crash handler
  447.     end;
  448.     
  449.     ## If 
  450.     if not(isUndefined(pParamList[4]))    # Will allow us to exit old style quicklook scripts
  451.         Throw pParamList[4];
  452. end;
  453.  
  454. #########################################################################
  455. #                            ReacquireTarget()
  456. #========================================================================
  457. # Author:        KTA
  458. # Description:    
  459. # Parameters:    None
  460. # Returns:        Nothing
  461. # Examples:        
  462. # Assumptions:    
  463. #########################################################################
  464. #========================================================================
  465. # History:
  466. #    ML    2/16/95    default pTargetName to global gMachineName
  467. #########################################################################
  468. Task ReacquireTarget(pTargetName := global gMachineName, pZoneName := "*")
  469. begin
  470.     returnVal := 0;
  471.     origTimeOut := CommandTimeOut(400);    # Set this too a large value in case it takes awhile to reboot or if 'Shutdown warning' is present.
  472.     result := acquireTarget(pTargetName, pZoneName);
  473.     if ((result = 0) or (result = 2))                # Reaquired target successfully
  474.     begin
  475.         # Need to wait till all inits get loaded.
  476.         while not _matchBoolean([menu])
  477.             wait(10);    
  478.         LogStr("Reaquired target successfully",4);
  479.         returnVal := 1;
  480.     end; 
  481.     
  482.     CommandTimeOut(origTimeOut);    
  483.     return(returnVal);
  484. end;
  485.  
  486. #########################################################################
  487. #                InstallEveryTimeMacro()
  488. #========================================================================
  489. #    Description:    Sends a Debug sting that invokes the everytime macro and
  490. #                    restarts the target if there was a crash.
  491. #    Parameters:        pMacroCommands - commands to be included in the everytime
  492. #                        macro which will execute when the target crashes.
  493. #    Returns:        nothing
  494. #    Examples:        InstallEveryTimeMacro('HOW; WH; TD; HT; SC;');
  495. #    Assumptions:    VU 2.1
  496. #========================================================================
  497. #    History:
  498. # KTA    2/13/95    Removed extra Printlns, check version of Macsbug, Quit Filetool.
  499. # KTA    2/16/95    Check for Macsbug 6.5xx, and insure macsbug is installed.
  500. # KTA    2/28/95    default pMacroCommands to global gMacroCommands
  501. #                try block around DebugStr() call.
  502. # ML    11/14/95 check $bff to see if macsbug is installed, replaced
  503. #                    Debug with _Debug
  504. #########################################################################
  505. Task InstallEveryTimeMacro(pMacroCommands := global gMacroCommands)
  506. begin
  507.     if not(global gCrashLog)
  508.     begin
  509.         global gBootVol :=    NameOfBootVolume();
  510.         global gCrashLog := "{gBootVol}:CRASHLOG";
  511.     end;
  512.     
  513.     tSysFolder := PathToSpecialFolder('macs');
  514.     correctMacsBugVersion := false;
  515.     macsbugInstalled := false;
  516.     if(DoesFileExist("{tSysFolder}Macsbug"))
  517.     begin
  518.         tMacsbugVers := _FileTool('ReadVersion',{"{tSysFolder}Macsbug", 1})[2][1];
  519.         QuitFileTool();
  520.         if(StrToNum(tMacsbugVers[1]) >= 6)
  521.         begin
  522.             if (StrToNum(tMacsbugVers[3]) >= 5)
  523.             begin
  524.                 correctMacsBugVersion := true;
  525.                 MemoryMonitorInit();
  526.                 if (_MemoryMonitor('ReadBytes',{ {0, 3071}, 4 })[2][1])
  527.                 # first byte at $bff is non-zero if macsbug is installed
  528.                 # $bff in decimal is 3071
  529.                 begin
  530.                     LogStr( "Installing EveryTime macro - SET scrollprompt off;MC everytime 'LOG ∂"{gCrashLog}∂";{pMacroCommands}; RB;LOG'; g"); 
  531.                     _DebugStr( "SET scrollprompt off;MC everytime 'LOG ∂"{gCrashLog}∂";{pMacroCommands}; RB;LOG'; g", true );
  532.                     macsbugInstalled := true;
  533.                 end; # if (_MemoryMonitor('ReadBytes',{ {0, 3071}, 4 })[1])
  534.                 else
  535.                     LogStr("!@#$% - MacsBug is not active");
  536.                 MemoryMonitorQuit();
  537.             end;
  538.         end;
  539.         if not (correctMacsBugVersion)
  540.             LogStr("!@#$% - Installing our Everytime macro requires MacsBug v6.5d8 or greater, you are using v{tMacsbugVers}");
  541.     end;
  542.     else
  543.     begin
  544.         LogStr("!@#$% - MacsBug is not in the system folder");
  545.         QuitFileTool();
  546.     end;
  547.         
  548.     if not (correctMacsBugVersion) or not (macsbugInstalled)
  549.     begin
  550.         LogStr("!@#$% - Turning our crashHandling mechanism - OFF");
  551.         global gCrashHandling := 0;
  552.     end;
  553. end;
  554.  
  555. #########################################################################
  556. #                GetRenameCrashLogAs()
  557. #========================================================================
  558. # Author:        ML
  559. # Description:    Accesser for getting the name that the crash log will
  560. #                be renamed as.
  561. # Parameters:    none
  562. # Returns:        gRenameCrashLogAs
  563. # Examples:        GetRenameCrashLogAs();
  564. # Assumptions:    None 
  565. #========================================================================
  566. # History:
  567. # 5/16/95    ML    created
  568. #########################################################################
  569. TASK GetRenameCrashLogAs()
  570. begin
  571.     return global gRenameCrashLogAs;
  572. end;
  573.  
  574. #########################################################################
  575. #                SetRenameCrashLogAs(pName)
  576. #========================================================================
  577. # Author:        ML
  578. # Description:    Accesser for setting the name that the crash log will
  579. #                be renamed as.
  580. # Parameters:    none
  581. # Returns:        none
  582. # Examples:        SetRenameCrashLogAs("my custom log name")
  583. # Assumptions:    None 
  584. #========================================================================
  585. # History:
  586. # 5/16/95    ML    created
  587. #########################################################################
  588. TASK SetRenameCrashLogAs(pName)
  589. begin
  590.     global gRenameCrashLogAs := pName;
  591. end;
  592.